<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Wait for and perform jobs</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="gearmanworker.wait.html">« GearmanWorker::wait</a></li>
      <li style="float: right;"><a href="class.gearmanexception.html">GearmanException »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.gearmanworker.html">GearmanWorker</a></li>
    <li>Wait for and perform jobs</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="gearmanworker.work" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">GearmanWorker::work</h1>
  <p class="verinfo">(PECL gearman &gt;= 0.5.0)</p><p class="refpurpose"><span class="refname">GearmanWorker::work</span> &mdash; <span class="dc-title">Wait for and perform jobs</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-gearmanworker.work-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>GearmanWorker::work</strong></span>(): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Waits for a job to be assigned and then calls the appropriate callback function.
   Issues an <strong><code>E_WARNING</code></strong> with the last Gearman error if the return
   code is not one of <strong><code>GEARMAN_SUCCESS</code></strong>, <strong><code>GEARMAN_IO_WAIT</code></strong>,
   or <strong><code>GEARMAN_WORK_FAIL</code></strong>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-gearmanworker.work-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-gearmanworker.work-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-gearmanworker.work-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4322">
    <p><strong>示例 #1 <span class="methodname"><strong>GearmanWorker::work()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">#&nbsp;create&nbsp;the&nbsp;worker<br /></span><span style="color: #0000BB">$worker&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">GearmanWorker</span><span style="color: #007700">();&nbsp;<br /><br /></span><span style="color: #FF8000">#&nbsp;add&nbsp;the&nbsp;default&nbsp;job&nbsp;server&nbsp;(localhost)<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">();&nbsp;<br /><br /></span><span style="color: #FF8000">#&nbsp;add&nbsp;the&nbsp;reverse&nbsp;function<br /></span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_reverse_function"</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #FF8000">#&nbsp;start&nbsp;te&nbsp;worker&nbsp;listening&nbsp;for&nbsp;job&nbsp;submissions<br /></span><span style="color: #007700">while&nbsp;(</span><span style="color: #0000BB">$worker</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">work</span><span style="color: #007700">());&nbsp;<br />&nbsp;<br />function&nbsp;</span><span style="color: #0000BB">my_reverse_function</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">)&nbsp;<br />{&nbsp;<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">strrev</span><span style="color: #007700">(</span><span style="color: #0000BB">$job</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">workload</span><span style="color: #007700">());&nbsp;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-gearmanworker.work-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="gearmanworker.addfunction.html" class="methodname" rel="rdfs-seeAlso">GearmanWorker::addFunction()</a> - Register and add callback function</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>